#pragma once
#include "stdafx.h"
#include "SamsungFreeCodecFilterConnection.h"

#define WM_GRAPHNOTIFY  WM_APP + 1

enum PlaybackState
{
    STATE_NO_GRAPH,
    STATE_RUNNING,
    STATE_PAUSED,
    STATE_STOPPED,
};

class VideoPlayerManager : public IMultiMediaDelegate
{
public:
	IGraphBuilder *pGraphBuilder;   //manages GraphFilter
	IMediaControl *pMediaControl;	//controls media
	IMediaSeeking *pMediaSeeking;	//manages time of media
	IMediaEventEx *pMediaEventEx;	//handle event of graph filter
	IBasicAudio   *pAudio;			//manages audio
	//draw video
	IBaseFilter				*pVmr, *pSF, *pRd, *pAr;		//
	IVMRWindowlessControl9  *pWC;		//
	IVMRFilterConfig9       *pConfig;	//
	
	
	SamsungFreeCodecFilterConnection m_ssFreeCodec;
	CWnd *m_wnd;
	CRect m_rtPlayer;
	CString m_strMediaFilePath;
	CString m_strSubtitleFilePath;
	long m_lTotalDuration;
	float m_fStep;
	long m_lTimeElapsed;
	int m_nPos;
	LONGLONG		m_length;
	PlaybackState   m_state;

	VideoPlayerManager(void);
	~VideoPlayerManager(void);
	virtual BOOL MultiMedia_Initialize(CString strPathName);
	virtual BOOL MultiMedia_Play();
	virtual BOOL MultiMedia_Pause();
	virtual BOOL MultiMedia_Stop();
	virtual BOOL MultiMedia_Resume(); 
	void         MultiMedia_Clean();

	HRESULT BlendApplicationText(HWND hwndApp, TCHAR *szNewText);
	BOOL PlayBack();
	void RenderVideoToWindowless(CWnd *pParentWnd, CRect pRect);
	void SetFilePath(CString strPath);
	void SetWindowParent(CWnd *wnd);
	void SetRectPlayer(CRect rtPlayer);
	CString GetTimeDuration(); 
	CString GetTimeElapsedOfMedia();
	long GetVolume();
	bool SetVolume(long lVol);
	CString SetPosition(int nPos);
	CString SetPosition2(LONGLONG cur);
	
	void OnBnClickedBtnShowCaption();
	
	HRESULT AddSubtitleFitler();
	bool IsSubtitleAvailable();
	
	HRESULT BuildFilterGraph(CWnd *pParentWnd, CRect pRect);
	HRESULT BuildGraphUsingDefault();
	HRESULT UpdateVideoWindow(const LPRECT prc);
};
